package net.caixiaomi.info.util;

import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import net.caixiaomi.info.app.CommonApp;

public class InitializeUtil {

    public static final String INITIALIZE_CATEGORY = "net.caixiaomi.info.initialize.category";

    public static boolean isAppLauncher(Intent intent) {
        try {
            ComponentName component = intent.getComponent();
            String intentClassName = component.getClassName();
            PackageManager packageManager = CommonApp.getInstance().getPackageManager();
            Intent launchIntentForPackage = packageManager.getLaunchIntentForPackage(CommonApp.getInstance().getPackageName());
            String launcherClassName = launchIntentForPackage.getComponent().getClassName();
            return TextUtils.equals(intentClassName, launcherClassName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    public static String getLaunchClassName() {
        try {
            PackageManager packageManager = CommonApp.getInstance().getPackageManager();
            Intent launchIntentForPackage = packageManager.getLaunchIntentForPackage(CommonApp.getInstance().getPackageName());
            String launcherClassName = launchIntentForPackage.getComponent().getClassName();
            return launcherClassName;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "";
    }


}
